package wowrl.data;



import java.awt.Point;
import java.awt.Rectangle;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import wowrl.engine.WOWRL_Engine;

public class WOWRL_Data {	
	//Size of game board, in tiles
	public static final int X_SIZE = 30;
	public static final int Y_SIZE = 40;
	public static final int MAX_X = X_SIZE-1;
	public static final int MAX_Y = Y_SIZE-1;
	public static final int MIN_X = 0;
	public static final int MIN_Y = 0;
	
	//Size of a tile, in pixels
	public static final int TILESIZE = 32;	
	
	//full game map (terrain,items,mobs)
	public GameMap map;
	
	//player's data
	public Player player;
	
	public Vector<String> messageLog;
	
	public WOWRL_Data(){	
		//Create the map
		map = new GameMap(X_SIZE,Y_SIZE);
		
		//Create the message log
		messageLog = new Vector<String>();
		
		//Add a default message
		messageLog.add("Welcome to WOW-RL!");
	}
	
	public Point getPlayerLocation()
	{
		return player.location;
	}
	
	public Point correctLocation(Point newLocation)
	{
		//Offset by +1 for greater-than checks because tile spills over 32 pixels from corner
		if ( (newLocation.x) > MAX_X){
			newLocation.x = MAX_X;
		}
		
		//Offset by +1 for greater-than checks because tile spills over 32 pixels from corner
		if ( (newLocation.y) > MAX_Y){
			newLocation.y = MAX_Y;
		}
		
		if ( newLocation.x < MIN_X){
			newLocation.x = MIN_X;
		}
		
		if ( newLocation.y < MIN_Y){
			newLocation.y = MIN_Y;
		}
		
		return newLocation;
	}
	
	public boolean validateLocation(Point location)
	{
		if ( location.x > MAX_X
	      || location.y > MAX_Y
		  || location.x < MIN_X
		  || location.y < MIN_Y)
		{
			return false;
		}
		
		return true;		
	}
	
	public boolean validateLocation(int xLoc, int yLoc) {
		return validateLocation(new Point(xLoc,yLoc));
	}
	
	public void setPlayerLocation(Point newLocation)
	{		
		//Validate coordinates - abort if invalid
		if (!validateLocation(newLocation)){return;}
		
		//Ensure the new location isn't solid, nor does it contain a mob
		if (map.terrain[newLocation.x][newLocation.y].isSolid || map.mobs[newLocation.x][newLocation.y] != null)
		{
			//If it is, don't change anything!
			return;
		}
		
		//Set the new location
		player.location = newLocation;
	}
}
